package io.renren.modules.api.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.annotation.SysLog;
import io.renren.common.exception.RRException;
import io.renren.common.utils.DateUtils;
import io.renren.common.utils.FileUtils;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.api.entity.WeixinNoEntity;
import io.renren.modules.api.service.WeixinNoService;
import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.api.entity.DnsParsingEntity;
import io.renren.modules.api.service.DnsParsingService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author owen
 * @email zhaoouyang@qq.com
 * @date 2018-05-31 15:18:07
 */
@RestController
@RequestMapping("api/dnsparsing")
public class DnsParsingController {
    @Autowired
    private DnsParsingService dnsParsingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:dnsparsing:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dnsParsingService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/listAll")
    @RequiresPermissions("api:dnsparsing:list")
    public R listAll(@RequestParam Map<String, Object> params){
        List<DnsParsingEntity> list=dnsParsingService.selectList(new EntityWrapper<DnsParsingEntity>());
        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:dnsparsing:info")
    public R info(@PathVariable("id") Integer id){
        DnsParsingEntity dnsParsing = dnsParsingService.selectById(id);
        return R.ok().put("dnsParsing", dnsParsing);
    }

    /**
     * 保存
     */
    @SysLog("保存域名绑定")
    @RequestMapping("/save")
    @RequiresPermissions("api:dnsparsing:save")
    public R save(@RequestBody DnsParsingEntity dnsParsing){
        dnsParsing.setCreatetime(DateUtils.getTime());
        dnsParsingService.insert(dnsParsing);
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改域名绑定")
    @RequestMapping("/update")
    @RequiresPermissions("api:dnsparsing:update")
    public R update(@RequestBody DnsParsingEntity dnsParsing){
        ValidatorUtils.validateEntity(dnsParsing);
        dnsParsingService.updateAllColumnById(dnsParsing);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除域名绑定")
    @RequestMapping("/delete")
    @RequiresPermissions("api:dnsparsing:delete")
    public R delete(@RequestBody Integer[] ids){
        dnsParsingService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
